//
//  BaseTabBarViewController.m
//  srproject
//
//  Created by liujianlong on 2022/7/25.
//

#import "BaseTabBarViewController.h"
#import "BaseNavigationController.h"
#import "RMineViewController.h"
#import "RCalendarViewController.h"
#import "RNotesViewController.h"

@interface BaseTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation BaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self setupColor];
    [self setupViewController];
    // Do any additional setup after loading the view.
}

- (void)setupColor{
//    self.tabBar.translucent = NO;
    self.tabBar.barTintColor = [UIColor whiteColor];
    self.tabBar.tintColor = [UIColor colorWithHexString:@"#2F88EE"];
    self.tabBar.unselectedItemTintColor = [UIColor colorWithHexString:@"#999999"];
}

- (void)setupViewController{
    RNotesViewController *vc1 = [[RNotesViewController alloc] init];
    vc1.type = NotesTypeNormal;
    RCalendarViewController *vc2 = [[RCalendarViewController alloc] init];
    RMineViewController *vc3 = [[RMineViewController alloc] init];
    
    NSArray *controllerArray = @[vc1,vc2,vc3];
    NSArray *titles = @[@"日记",@"日历",@"我的"];
    NSArray *imgs = @[@"rj",@"rl",@"wd"];
    NSArray *selectimgs = @[@"rj-xz",@"rl-xz",@"wd-xz"];
    for (int i = 0; i < controllerArray.count; i++) {
        UIViewController *vc = controllerArray[i];
        vc.tabBarItem = [[UITabBarItem alloc] init];
        vc.tabBarItem.title = LS(titles[i]);
        vc.tabBarItem.image = [[UIImage imageNamed:imgs[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectimgs[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
        nav.navigationBar.hidden = i == 2;
        [self addChildViewController:nav];
    }
}

#pragma mark - UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    UINavigationController *navi = (UINavigationController *)viewController;
    //    if ([NSStringFromClass([navi.topViewController class]) isEqualToString:@"SWCameraViewController"]) {
    //        SWCameraViewController *vc = [[SWCameraViewController alloc] init];
    //        vc.modalPresentationStyle = UIModalPresentationFullScreen;
    //        [navi.topViewController presentViewController:vc animated:YES completion:nil];
    //        return NO;
    //    }
    return YES;
}
@end
